import { apiClient } from './apiClient';

// 热点数据相关接口
export interface HotPlatform {
  name: string;
  platform_name: string;
  type: string;
  description: string;
  available: boolean;
}

export interface PlatformsResponse {
  platforms: HotPlatform[];
  count: number;
  updated_at: string;
}

export interface HotItem {
  index: number;
  title: string;
  url: string;
  hot?: string | number;
  desc?: string;
  pic?: string;
  timestamp?: string;
}

export interface HotResponse {
  platform: string;
  subtitle: string;
  update_time: string;
  data: HotItem[];
}

export const hotApi = {
  // 获取所有平台信息
  getPlatforms: (): Promise<PlatformsResponse> =>
    apiClient.get('/hot/platforms'),

  // 获取指定平台的热点数据
  getPlatformData: (platform: string, limit?: number): Promise<HotResponse> =>
    apiClient.get(`/hot/${platform}`, limit ? { limit } : undefined),

  // 批量获取多个平台的热点数据
  getAllPlatformData: (platforms?: string[], limit?: number): Promise<Record<string, HotResponse>> => {
    const params: Record<string, string | number> = {};
    if (limit) params.limit = limit;
    if (platforms && platforms.length > 0) {
      // 将平台数组转换为查询参数
      return apiClient.get('/hot', { ...params, platforms: platforms.join(',') });
    }
    return apiClient.get('/hot', params);
  },

  // 刷新指定平台的缓存
  refreshPlatformCache: (platform: string): Promise<{ message: string }> =>
    apiClient.post(`/hot/refresh/${platform}`),

  // 刷新所有平台的缓存
  refreshAllCache: (): Promise<{ message: string }> =>
    apiClient.post('/hot/refresh'),
};